<?php echo $this->fetch('header.html'); ?>
<div id="rightTop">
    <p>统计</p>
    <?php echo $this->fetch('subnav.html'); ?>
</div>
<div class="mrightTop">
    <div class="fontl">
        <form method="get">
            <div class="left">
                <input type="hidden" name="app" value="stat_trade" />
                <input type="hidden" name="act" value="goods" />

                <div class="left">
                    <select name="rank_type" id="rank_type" class="querySelect">
                        <option value="trade_num" <?php if ($this->_var['search_arr']['rank_type'] == 'trade_num'): ?>selected<?php endif; ?>>订单量统计</option>
                        <option value="trade_amount" <?php if ($this->_var['search_arr']['rank_type'] == 'trade_amount'): ?>selected<?php endif; ?>>销售额统计</option>
                    </select>
                </div>
                <div class="left">
                    <select name="search_type" id="search_type" class="querySelect">
                        <option value="day" <?php if ($this->_var['search_arr']['search_type'] == 'day'): ?>selected<?php endif; ?>>按照天统计</option>
                        <option value="week" <?php if ($this->_var['search_arr']['search_type'] == 'week'): ?>selected<?php endif; ?>>按照周统计</option>
                        <option value="month" <?php if ($this->_var['search_arr']['search_type'] == 'month'): ?>selected<?php endif; ?>>按照月统计</option>
                    </select>
                </div>
                <div id="searchtype_day" style="display:none;" class="left">
                    <input class="txt date" type="text" value="<?php echo $this->_var['search_time']; ?>" id="search_time" name="search_time">
                </div>
                <div id="searchtype_week" style="display:none;" class="left">
                    <select name="search_time_year" class="querySelect">
                        <?php $_from = $this->_var['year_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['current_year'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                    <select name="search_time_month" class="querySelect">
                        <?php $_from = $this->_var['month_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['current_month'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                    <select name="search_time_week" class="querySelect">
                        <?php $_from = $this->_var['week_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['v']['key']; ?>" <?php if ($this->_var['current_week'] == $this->_var['v']['key']): ?>selected<?php endif; ?>><?php echo $this->_var['v']['val']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                </div>

                <div id="searchtype_month" style="display:none;" class="left">
                    <select name="search_time_year" class="querySelect">
                        <?php $_from = $this->_var['year_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['current_year'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                    <select name="search_time_month" class="querySelect">
                        <?php $_from = $this->_var['month_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['current_month'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                </div>
                <input type="submit" class="formbtn" value="查询" />
                <input type="hidden" id="export_type" name="export_type" data-param='{"url":"<?php echo $this->_var['actionurl']; ?>&exporttype=excel"}' value="excel"/>
                <a class="btn1" href="javascript:void(0);" id="export_btn"><span>导出Excel</span></a>
            </div>
        </form>
    </div>
</div>
<div class="stat_info">
    <span>上架商品数：<strong><?php echo $this->_var['goods_on_allnum']; ?></strong></span><span>下单商品数：<strong><?php echo ($this->_var['order_goods_num'] == '') ? '0' : $this->_var['order_goods_num']; ?></strong></span><span>下单单数：<strong><?php echo $this->_var['order_num']; ?></strong></span><span>下单客户数：<strong><?php echo ($this->_var['order_buyer_num'] == '') ? '0' : $this->_var['order_buyer_num']; ?></strong></span><span>合计金额：<strong><?php echo price_format($this->_var['order_amount']); ?></strong>元</span>
</div>
<div class="tdare">
    <div id="container" class="" style="height:400px"></div>
</div>
<div class="tdare">
    <table width="100%" cellspacing="0" class="dataTable">
        <thead>
            <tr class="tatr1">
                <td class="firstCell">排名</td>
                <td>商品名称</td>
                <td><?php echo $this->_var['table_tip']; ?></td>
            </tr>
        </thead>
        <tbody id="datatable">
            <?php if ($this->_var['goods_list']): ?>
            <?php $_from = $this->_var['goods_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');$this->_foreach['name'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['name']['total'] > 0):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
        $this->_foreach['name']['iteration']++;
?>
            <tr class="tatr2">
                <td class="firstCell"><?php echo $this->_foreach['name']['iteration']; ?></td>
                <td><?php echo htmlspecialchars($this->_var['v']['goods_name']); ?></td>
                <td><?php echo htmlspecialchars($this->_var['v']['allnum']); ?></td>
            </tr>
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
            <?php else: ?>
            <tr class="no_data">
                <td colspan="12">没有符合条件的记录</td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
    <div class="pageLinks"><?php echo $this->fetch('page.bottom.html'); ?></div>
</div>
<script>
    $(function() {
        //统计数据类型
        var s_type = $("#search_type").val();
        $('#search_time').datepicker({dateFormat: 'yy-mm-dd'});

        show_searchtime();
        $("#search_type").change(function() {
            show_searchtime();
        });
        //展示搜索时间框
        function show_searchtime() {
            s_type = $("#search_type").val();
            $("[id^='searchtype_']").hide();
            $("#searchtype_" + s_type).show();
        }

        //更新周数组
        $("[name='search_time_month']").change(function() {
            var year = $("[name='search_time_year']").val();
            var month = $("[name='search_time_month']").val();
            $("[name='search_time_week']").html('');
            $.getJSON('index.php?app=stat_member&act=getweekofmonth', {y: year, m: month}, function(data) {
                if (data != null) {
                    for (var i = 0; i < data.length; i++) {
                        $("[name='search_time_week']").append('<option value="' + data[i].key + '">' + data[i].val + '</option>');
                    }
                }
            });
        });
        $('select[name="search_time_year"]').change(function() {
            var s_year = $(this).val();
            $('select[name="search_time_year"]').each(function() {
                $(this).val(s_year);
            });
        });
        $('select[name="search_time_month"]').change(function() {
            var s_month = $(this).val();
            $('select[name="search_time_month"]').each(function() {
                $(this).val(s_month);
            });
        });

        $('#container').highcharts(<?php echo $this->_var['stat_json']; ?>);

        //导出图表
        $("#export_btn").click(function() {
            var item = $("#export_type");
            var type = $(item).val();
            if (type == 'excel') {
                download_excel(item);
            }
        });
    });
</script>


<?php echo $this->fetch('footer.html'); ?>